package org.hrc.puzzleGame.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
   private static Connection con;
    // jdbc驱动
   private static String driver = "com.mysql.cj.jdbc.Driver";
    // 这里我的数据库是cxxt
   private static String url = "jdbc:mysql://localhost:3306/puzzleGame?&useSSL=false&serverTimezone=UTC";
   private static String user = "root";
   private static String password = "root";
    /**加载驱动*/
    static {
        try {
            // 注册JDBC驱动程序
            Class.forName(driver);
            // 建立连接
            con = DriverManager.getConnection(url, user, password);
            if (!con.isClosed()) {
                System.out.println("数据库连接成功");
            }
        } catch (ClassNotFoundException e) {
            System.out.println("数据库驱动没有安装");

        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("数据库连接失败");
        }
    }
    public static  Connection getConnection() {
        return con;
    }
}
